package com.big.patient.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big.model.model.buyer.BuyerPhotoCord;
import com.big.model.model.merchandise.MerchandiseDetail;
import com.big.model.model.patient.PatientInfo;
import com.big.patient.mapper.BuyerPhotoCordMapper;
import com.big.patient.service.BuyerPhotoCordService;
import com.big.patient.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BuyerPhotoCordServiceImpl extends ServiceImpl<BuyerPhotoCordMapper, BuyerPhotoCord> implements BuyerPhotoCordService {


    @Autowired
    PatientService patientService;

    /**
     * 买家秀照片组
     * @param page
     * @return
     */
    @Override
    public IPage<BuyerPhotoCord> buyerPhotoCordsInfos(Page<BuyerPhotoCord> page,String mId) {
        QueryWrapper<BuyerPhotoCord>wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(mId)) {
           wrapper.select("buyer_m_url_site","p_id").eq("m_id",mId);
        }
        //调用mapper方法
        IPage<BuyerPhotoCord> pages = baseMapper.selectPage(page,wrapper);
        pages.getRecords().forEach(item -> {
            this.patientInfos(item);
        });
        return pages;
    }


    /**
     * 查用户信息
     */
    public BuyerPhotoCord patientInfos(BuyerPhotoCord buyer){
        PatientInfo userInfoById = patientService.findUserInfoById(String.valueOf(buyer.getPId()));
        buyer.getParam().put("patient",userInfoById);
        return buyer;
    }

}
